home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 019a / tde10src.zip / HWIND.C < prev    next >
C/C++ Source or Header  |  1991-06-05  |  12KB  |  383 lines

  1. /*******************  start of original comments  ********************/
  2. /*
  3.  * Written by Douglas Thomson (1989/1990)
  4.  *
  5.  * This source code is released into the public domain.
  6.  */
  7.  
  8. /*
  9.  * Name:    hardware independent screen IO module
  10.  * Purpose: This file contains the code to interface the rest of the
  11.  *           editor to the display and input hardware.
  12.  * File:    hwind.c
  13.  * Author:  Douglas Thomson
  14.  * System:  this file is intended to be system-independent
  15.  * Date:    October 2, 1989
  16.  * Notes:   This is the only module that is allowed to call the hardware
  17.  *           dependent display IO library.
  18.  *          Typically, functions here check whether any action is
  19.  *           necessary (for example, the cursor may already happen to be
  20.  *           in the required position), call hardware dependent functions
  21.  *           to achieve the required effect, and finally update status
  22.  *           information about the current state of the terminal display.
  23.  *          The idea behind this approach is to keep the hardware
  24.  *           dependent code as small and simple as possible, thus making
  25.  *           porting the code easier.
  26.  */
  27. /*********************  end of original comments   ********************/
  28.  
  29.  
  30. /*
  31.  * Some routines were added to display current editor modes in the lite bar
  32.  * at the bottom of the screen. Other routines were rewritten in assembly.
  33.  * I feel the need for speed.
  34.  *
  35.  * New editor name:  tde, the Thomson-Davis Editor.
  36.  * Author:           Frank Davis
  37.  * Date:             June 5, 1991
  38.  *
  39.  * This modification of Douglas Thomson's code is released into the
  40.  * public domain, Frank Davis.  You may distribute it freely.
  41.  */
  42.  
  43. #include "tdestr.h"
  44. #include "common.h"
  45. #include "tdefunc.h"
  46.  
  47. /*
  48.  * Name:    xygoto
  49.  * Purpose: To move the cursor to the required column and line.
  50.  * Date:    October 2, 1989
  51.  * Passed:  col:    desired column (0 up to max)
  52.  *          line:   desired line (0 up to max)
  53.  * Notes:   This function makes some attempt to use shorter movement
  54.  *           commands for simple movements (initially, only backspace
  55.  *           to move left one space).
  56.  */
  57. void xygoto( col, line )
  58. int col;
  59. int line;
  60. {
  61.    g_display.col = col;
  62.    g_display.line = line;
  63.    hw_xygoto( );
  64. }
  65.  
  66. /*
  67.  * Name:    save_screen_line
  68.  * Purpose: To save the characters and attributes of a line on screen.
  69.  * Date:    June 5, 1991
  70.  * Notes:   No need to redraw entire screen to show a prompt.  Just save
  71.  *          the contents of the line on screen where prompt is to be displayed
  72.  */
  73. void save_screen_line( int col, int line, char *screen_buffer )
  74. {
  75. char far *p;
  76.  
  77.    p = g_display.display_address + line * 160 + col * 2;
  78.    memcpy( screen_buffer, p, 160 );
  79. }
  80.  
  81. /*
  82.  * Name:    restore_screen_line
  83.  * Purpose: To restore the characters and attributes of a line on screen.
  84.  * Date:    June 5, 1991
  85.  * Notes:   No need to redraw entire screen to show a prompt.  Just save
  86.  *          the contents of the line on screen where prompt is to be displayed
  87.  */
  88. void restore_screen_line( int col, int line, char *screen_buffer )
  89. {
  90. char far *p;
  91.  
  92.    p = g_display.display_address + line * 160 + col * 2;
  93.    memcpy( p, screen_buffer, 160 );
  94. }
  95.  
  96. /*
  97.  * Name:    force_blank
  98.  * Purpose: To set the status of the screen so that nothing can appear to
  99.  *           be what it needs to be, so that the entire screen will be
  100.  *           redrawn.
  101.  * Date:    June 5, 1991
  102.  * Notes:   Call the video BIOS routine to clear the screen.
  103.  */
  104. void force_blank( )
  105. {
  106. int line;
  107.  
  108.    line = g_display.nlines+1;
  109.    _asm {
  110.         xor     ch, ch                  ; starting row in ch = 0
  111.         xor     cl, cl                  ; starting column in cl = 0
  112.         mov     ax, WORD PTR line       ; get ending row
  113.         mov     dh, al                  ; put it in dh
  114.         mov     dl, 79                  ; ending column in dl = 79
  115.         mov     bh, 7                   ; attribute in bh  = 7 (normal)
  116.         mov     al, 0                   ; get number of lines
  117.         mov     ah, 6                   ; get function number
  118.         push    bp                      ; some dos versions wipeout bp
  119.         int     0x10
  120.         pop     bp
  121.    }
  122. }
  123.  
  124. /*
  125.  * Name:    initialize
  126.  * Purpose: To initialize all the screen status info that is not hardware
  127.  *           dependent, and call the hardware initialization routine to
  128.  *           pick up the hardware dependent stuff.
  129.  * Date:    June 5, 1991
  130.  * Returns: [g_status and g_display]: all set up ready to go
  131.  * Notes:   It is assumed that g_status and g_display are all \0's to begin
  132.  *           with (the default if they use static storage). If this may
  133.  *           not be the case, then clear them explicitly here.
  134.  */
  135. void initialize( )
  136. {
  137.    /*
  138.     * we do not know where the cursor is yet
  139.     */
  140.    g_display.col = -1;
  141.    g_display.line = -1;
  142.  
  143.    /*
  144.     * do the hardware initialization first, since this allocates the main
  145.     *  text buffer and sets up other info needed here later.
  146.     */
  147.    hw_initialize( );
  148.  
  149.    bm.search_defined = ERROR;
  150.    bm.search_case = IGNORE;
  151.    /*
  152.     * the main text buffer must be preceded by a ^Z, so that backward
  153.     *  searches can see the start of the text buffer
  154.     */
  155.    *g_status.start_mem++ = CONTROL_Z;
  156.  
  157.    /*
  158.     * most of the system's text pointers are safer set to the start
  159.     *  of the text buffer - some of these may not be strictly
  160.     *  necessary.
  161.     */
  162.    g_status.temp_end = g_status.start_mem;
  163.    g_status.end_mem = g_status.start_mem;
  164.  
  165.    /*
  166.     * set the default modes - may want to read this from a file later
  167.     */
  168.    g_status.insert = TRUE;
  169.    g_status.indent = TRUE;
  170.    g_status.marked = FALSE;
  171.    g_status.marked_file = NULL;
  172.  
  173.    g_status.current_window = NULL;
  174.    g_status.current_file = NULL;
  175.    g_status.window_list = NULL;
  176.    g_status.file_list = NULL;
  177.    g_status.file_count = 0;
  178.  
  179.    /*
  180.     * set default interval between tabs
  181.     */
  182.    g_status.tab_size = 8;
  183.  
  184.    /*
  185.     * set the number of lines from one page that should still be visible
  186.     *  on the next page after page up or page down.
  187.     */
  188.    g_status.overlap = 1;
  189.  
  190.    /*
  191.     * clear the screen and show the author's names
  192.     */
  193.    force_blank( );
  194.    show_credits( );
  195. }
  196.  
  197.  
  198. /*
  199.  * Name:    show_modes
  200.  * Purpose: show current editor modes in lite bar at bottom of screen
  201.  * Date:    June 5, 1991
  202.  */
  203. void show_modes( )
  204. {
  205. char status_line[MAX_COLS+2];
  206. char *p;
  207.  
  208.    memset( status_line, ' ', MAX_COLS );
  209.    status_line[MAX_COLS] = '\0';
  210.    status_line[78] = (g_status.insert == TRUE) ? 'i' : 'o';
  211.    s_output( status_line, g_display.mode_line, 0, g_display.mode_color );
  212.    s_output( "Files = ", g_display.mode_line, 1, g_display.mode_color );
  213.    s_output( "memory = ", g_display.mode_line, 13, g_display.mode_color );
  214.    show_file_count( g_status.file_count );
  215.    show_avail_mem( );
  216.    show_indent_mode( );
  217.    show_search_case( );
  218. }
  219.  
  220.  
  221. /*
  222.  * Name:    show_file_count
  223.  * Purpose: show number of open files in lite bar at bottom of screen
  224.  * Date:    June 5, 1991
  225.  */
  226. void show_file_count( fc )
  227. int fc;
  228. {
  229. char status_line[MAX_COLS+2];
  230. int mode_line, mode_color;
  231.  
  232.    mode_line = g_display.mode_line;
  233.    mode_color = g_display.mode_color;
  234.    s_output( "  ", mode_line, 9, mode_color );
  235.    s_output( itoa( fc, status_line, 10 ), mode_line, 9, mode_color );
  236. }
  237.  
  238.  
  239. /*
  240.  * Name:    show_avail_mem
  241.  * Purpose: show available free memory in lite bar at bottom of screen
  242.  * Date:    June 5, 1991
  243.  */
  244. void show_avail_mem( )
  245. {
  246. char memory[MAX_COLS+2];
  247. int mode_line, mode_color;
  248. unsigned long avail;
  249.  
  250.    avail = ptoul( g_status.max_mem ) - ptoul( g_status.end_mem );
  251.    ultoa( avail, memory, 10 );
  252.    mode_line = g_display.mode_line;
  253.    mode_color = g_display.mode_color;
  254.    s_output( "        ", mode_line, 22, mode_color );
  255.    s_output( memory, mode_line, 22, mode_color );
  256. }
  257.  
  258.  
  259. /*
  260.  * Name:    show_indent_mode
  261.  * Purpose: show indent mode in lite bar at bottom of screen
  262.  * Date:    June 5, 1991
  263.  */
  264. void show_indent_mode( )
  265. {
  266. int mode_line, mode_color;
  267.  
  268.    mode_line = g_display.mode_line;
  269.    mode_color = g_display.mode_color;
  270.    if (g_status.indent)
  271.       s_output( "Indent", mode_line, 32, mode_color );
  272.    else
  273.       s_output( "      ", mode_line, 32, mode_color );
  274. }
  275.  
  276.  
  277. /*
  278.  * Name:    show_search_case
  279.  * Purpose: indicate whether to ignore or match case on search strings
  280.  * Date:    June 5, 1991
  281.  */
  282. void show_search_case( )
  283. {
  284. int mode_line, mode_color;
  285.  
  286.    mode_line = g_display.mode_line;
  287.    mode_color = g_display.mode_color;
  288.    if (bm.search_case == IGNORE)
  289.       s_output( "Ignore", mode_line, 42, mode_color );
  290.    else
  291.       s_output( "Match ", mode_line, 42, mode_color );
  292. }
  293.  
  294.  
  295. /*
  296.  * Name:    terminate
  297.  * Purpose: To do any hardware independent housekeeping, and call the
  298.  *           hardware dependent code to clean up screen modes and leave
  299.  *           the cursor at the bottom of the screen in normal attribute.
  300.  * Date:    October 2, 1989
  301.  * Notes:   At present, there is nothing apart from hardware dependent
  302.  *           code required.
  303.  */
  304. void terminate( )
  305. {
  306.    hw_terminate( );
  307. }
  308.  
  309. /*
  310.  * Name:    window_scroll_up
  311.  * Purpose: To scroll all the lines between top and bottom up one line.
  312.  * Date:    June 5, 1991
  313.  * Passed:  top:    top line to be scrolled
  314.  *          bottom: bottom line to be scrolled
  315.  * Notes:   Call the video BIOS routine to scroll window up.
  316.  */
  317. void window_scroll_up( top, bottom )
  318. int top;
  319. int bottom;
  320. {
  321.  
  322.    _asm {
  323.         mov     ax, WORD PTR top        ; get starting row
  324.         mov     ch, al                  ; put it in ch
  325.         xor     cl, cl                  ; startin column in cl = 0
  326.         mov     ax, WORD PTR bottom     ; get ending row
  327.         mov     dh, al                  ; put it in dh
  328.         mov     dl, 79                  ; ending column in dl = 79
  329.         mov     bh, 7                   ; attribute in bh  = 7 (normal)
  330.         mov     al, 1                   ; get number of lines
  331.         mov     ah, 6                   ; get function number
  332.         push    bp
  333.         int     0x10
  334.         pop     bp
  335.    }
  336. }
  337.  
  338. /*
  339.  * Name:    window_scroll_down
  340.  * Purpose: To scroll all the lines between top and bottom down one line.
  341.  * Date:    June 5, 1991
  342.  * Passed:  top:    top line to be scrolled
  343.  *          bottom: bottom line to be scrolled
  344.  * Notes:   Call the video BIOS routine to scroll window down.
  345.  */
  346. void window_scroll_down( top, bottom )
  347. int top;
  348. int bottom;
  349. {
  350.  
  351.    _asm {
  352.         mov     ax, WORD PTR top        ; get starting row
  353.         mov     ch, al                  ; put it in ch
  354.         xor     cl, cl                  ; put starting column in cl - 0
  355.         mov     ax, WORD PTR bottom     ; get ending row
  356.         mov     dh, al                  ; put it in dh
  357.         mov     dl, 79                  ; put ending column in dl
  358.         mov     bh, 7                   ; put attribute in bh
  359.         mov     ah, 7                   ; get function number
  360.         mov     al, 1                   ; get number of lines
  361.         push    bp
  362.         int     0x10
  363.         pop     bp
  364.    }
  365. }
  366.  
  367.  
  368. /*
  369.  * Name:    combine_strings
  370.  * Purpose: stick 3 strings together
  371.  * Date:    June 5, 1991
  372.  * Passed:  buff:    buffer to hold concatenation of 3 strings
  373.  *          s1:  pointer to string 1
  374.  *          s2:  pointer to string 2
  375.  *          s3:  pointer to string 3
  376.  */
  377. void combine_strings( char *buff, char *s1, char *s2, char *s3 )
  378. {
  379.    strcpy( buff, s1 );
  380.    strcat( buff, s2 );
  381.    strcat( buff, s3 );
  382. }
  383.